home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / tcp_ip / rip2 / ripdump.c < prev    next >
C/C++ Source or Header  |  1993-09-28  |  2KB  |  91 lines

  1. /* RIP packet tracing
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  *
  4.  *    Changes Copyright (c) 1993 Jeff White - N0POY, All Rights Reserved.
  5.  *    Permission granted for non-commercial copying and use, provided
  6.  *    this notice is retained.
  7.  *
  8.  * Rehack for RIP-2 (RFC1388) by N0POY 4/1993
  9.  *
  10.  * Beta release 9/8/93 V0.91
  11.  *
  12.  */
  13. #include "global.h"
  14. #include "config.h"
  15. #ifdef RIP
  16. #include "mbuf.h"
  17. #include "netuser.h"
  18. #include "timer.h"
  19. #include "rip.h"
  20. #include "trace.h"
  21.  
  22. // from trace.c
  23. void fmtline __ARGS((FILE *fp,int16 addr,char *buf,int16 len));
  24.  
  25. void
  26. rip_dump(fp,bpp)
  27. FILE *fp;
  28. struct mbuf **bpp;
  29. {
  30.    struct rip_route entry;
  31.    struct rip_authenticate *ripauth;
  32.    int i;
  33.    int cmd,version;
  34.    int16 len;
  35.    int16 domain;
  36.    char ipaddmask[25];
  37.        
  38.    fprintf(fp,"RIP: ");
  39.    cmd = PULLCHAR(bpp);
  40.    version = PULLCHAR(bpp);
  41.    switch(cmd){
  42.    case RIPCMD_REQUEST:
  43.       fprintf(fp,"REQUEST");
  44.       break;
  45.    case RIPCMD_RESPONSE:
  46.       fprintf(fp,"RESPONSE");
  47.       break;
  48.    default:
  49.       fprintf(fp," cmd %u",cmd);
  50.       break;
  51.    }
  52.  
  53.    domain = pull16(bpp);
  54.  
  55.    len = len_p(*bpp);
  56.    fprintf(fp," vers %u entries %u domain %u:\n",version,len / RIP_ENTRY, domain);
  57.  
  58.     i = 0;
  59.     while(len >= RIP_ENTRY){
  60.         /* Pull an entry off the packet */
  61.         pullentry(&entry,bpp);
  62.         len -= RIP_ENTRY;
  63.  
  64.       if (entry.rip_family == RIP_AF_AUTH) {
  65.          continue;
  66.       }
  67.  
  68.         if(entry.rip_family != RIP_AF_INET) {
  69.             /* Skip non-IP addresses */
  70.             continue;
  71.         }
  72.    
  73.       if (version >= RIP_VERSION_2) {
  74.          sprintf(ipaddmask, "%s/%-4d", inet_ntoa(entry.rip_dest),
  75.             mask2width(entry.rip_dest_mask));
  76.       } else {
  77.          sprintf(ipaddmask, "%s/??", inet_ntoa(entry.rip_dest));
  78.       }
  79.         fprintf(fp,"%-20s%-3u",ipaddmask, entry.rip_metric);
  80.  
  81.         if((++i % 3) == 0){
  82.             putc('\n',fp);
  83.         }
  84.     }
  85.     if((i % 3) != 0)
  86.         putc('\n',fp);
  87. }
  88. #endif /* RIP */
  89.  
  90.  
  91.